/**
 * 
 */
var cryptoapp = angular.module('cryptoapp', []);

 function userControllerConstrustor($scope, $http)
{
	/*
	$scope.users = 
		[
		 {
			 "username" : "ng-hardcoded-01",
			 "publicKey" : "1234567890"
		 },
		 {
			 "username" : "ng-hardcoded-02",
			 "publicKey" : "1234567890"
		 }
		];
	*/
	
	$http.get('user/all').success( function(data){
		$scope.users = data;
		$scope.orderProp = 'username';
	} );
}

function conversationControllerConstructor($scope, $http)
{
	$scope.completeText = "This is a harcoded text sample";
	var conversationWebSocket = new WebSocket('ws://localhost:8080/cryptochat/ws');
	
	conversationWebSocket.onopen = function(event)
	{
		console.log("opening websocket");
		conversationWebSocket.send("test message");
	};
	
	conversationWebSocket.onclose = function(event)
	{
		console.log("closing websocket");
	};
	
	conversationWebSocket.onmessage = function(event)
	{
		console.log("received: " + event.data);
	};
}

cryptoapp.controller('usersController', userControllerConstrustor);
cryptoapp.controller('conversationController', conversationControllerConstructor);

function threeApp()
{
	var scene = new THREE.Scene();
	var camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
	var renderer = new THREE.WebGLRenderer();
//	var light = new THREE.Light(0xffffff);
	
	renderer.setSize(window.innerWidth, window.innerHeight);
	document.body.appendChild(renderer.domElement);
	
	scene.add( new THREE.AmbientLight( 0x222222 ) );
	
	var geometry = new THREE.CubeGeometry(1, 1, 1);
	var material = new THREE.MeshBasicMaterial( {color : 0x00f233} );
	var cube = new THREE.Mesh(geometry, material);
	scene.add(cube);
	
	geometry = new THREE.CubeGeometry(2,4,1);

	material = new THREE.MeshBasicMaterial({ color : 0xff1133});
	var parall = new THREE.Mesh(geometry, material);
	parall.position.x = 2;
	scene.add(parall);
	
	camera.position.z = 5;
	
	
	function render()
	{
		requestAnimationFrame(render);
		
		cube.rotation.x += 0.05;
		cube.rotation.y += 0.03;
		
		parall.rotation.z += 0.04;
		parall.rotation.y +=.01
		
		renderer.render(scene, camera);
	}
	render();
}